package com.esunny.db.hbase;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Random;

public class ReadAction extends Action {

    private Random                  random = new Random();
    private HashMap<String, String> result = null;
    private HashSet<String>         fields = null;

    @Override
    public void before() {
        int keynum = random.nextInt(this.keySpace);
        key = "user" + keynum;
        result = new HashMap<String, String>();
        HashSet<String> s = new HashSet<String>();
        for (int i = 1; i < this.fieldSize; i++) {
            s.add("field" + i);
        }
        fields = s;
    }

    @Override
    public int execute() {
        return cli.read(this.tableName, key, fields, result);
    }

    @Override
    public void after() {
        result = null;
        fields = null;
    }

}
